Sodamhan.com

TL;DR

[[

Check file types and compare values. Returns a status of 0 if the condition evaluates to true, 1 if it evaluates to false. More information: https://gnu.org/software/bash/manual/bash.html#index-_005b_005b.

  • Test if a given variable is equal/not equal to the specified string:

[[ $variable ==|!= "string" ]]

  • Test if a given string conforms the specified glob/regex:

[[ $variable ==|=~ pattern ]]

  • Test if a given variable is equal/not equal/greater than/less than/greater than or equal/less than or equal to the specified number:

[[ $variable -eq|ne|gt|lt|ge|le integer ]]

  • Test if the specified variable has a non-empty value:

[[ -n $variable ]]

  • Test if the specified variable has an empty value:

[[ -z $variable ]]

  • Test if the specified file exists:

[[ -f path/to/file ]]

  • Test if the specified directory exists:

[[ -d path/to/directory ]]

  • Test if the specified file or directory exists:

[[ -e path/to/file_or_directory ]]

This document was created using the contents of the tldr project.